import tkinter as tk
import numpy as np
import Animations
ar=np.array



class View(tk.Frame):
    def __init__(self,father,pos=ar([0,0]),size=ar([100,100])):
        self.father=father
        super().__init__(father)
        self.pack()
        self.canvas=tk.Canvas(self,bg='green',width=size[0],height=size[1])
        self.canvas.pack()
        self.subviews=[]
        self.animations={}
        self.place(x=pos[0],y=pos[1],width=size[0],height=size[1])
        self.pos=pos
        self.size=size
    def addSubView(self,view):
        self.subviews.append(view)
    def __setattr__(self,name,value):
        if name=='size':
            self.__dict__[name]=value
            self.place(width=value[0],height=value[1])
        elif name=='pos':
            self.__dict__[name]=value
            self.place(x=value[0],y=value[1],anchor=tk.NW)
        else:
            self.__dict__[name]=value
        
       
root=tk.Tk()
root.geometry("800x600")

a=View(root)
a.canvas.bg='green'
a.canvas.pack()
a.pos=ar([300,450])
a.size=ar([200,100])

def bounce():
    bounceAnimation=Animations.Bounce(
        view=a,
        destpos=ar([300,500]),
        phyinfo=Animations.PhysicsInfo(
            view=a,
            v=ar([0,-30])
        ),
        finishCallBack=lambda : print("Animation Done. ")
    )
    bounceAnimation.play()

b=tk.Button(root,command=bounce)
b.pack()

root.mainloop()